import axios from 'axios'
import nprogress from 'nprogress'
import store from '../store'
import 'nprogress/nprogress.css'//引入进度条的样式文件,可以在他的css文件下修改进度条的颜色
console.log(nprogress)
const requests=axios.create({
    baseURL:'/api',
    timeout:5000,
});
requests.interceptors.request.use((config)=>{
    if(store.state.detail.uuid_token){
        config.headers.userTempId=store.state.detail.uuid_token//给请求头添加uuid随机数
    }
    if(store.state.user.token){
        config.headers.token=store.state.user.token//给请求头添加token
    }
    nprogress.start()//进度条的开始
    console.log(config)
    return config;
})
requests.interceptors.response.use((res)=>{
    nprogress.done()//进度条的结束
    return res;
},(error)=>{
    return Promise.reject(new Error('faile'))
});
export default requests
